package com.fintech.third.utils;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * 类说明：SerialNum查询流水号生产器
 * @date 2017年3月18日
 * @author SHAOYUN
 *
 **/

public class SerialNumCreater implements Serializable{
	

	private static final long serialVersionUID = 1L;

	/**
	 * 
	 * @param type 第三方接口名称缩写
	 * @param loanId 申请单号
	 * @return
	 */
	public static String creater(String type,String loanId) {
		 StringBuffer sb = new StringBuffer();
	     Date date = new Date();
	     DateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
	     StringBuilder stringBuilder=new StringBuilder();
	     if(type.length()>5){
	    	 type=type.substring(0,5);
	     }
	     for(int i=0;i<5-type.length();i++){
	    	 stringBuilder.append("0");
	     }
	     sb.append(type).append(stringBuilder.toString()).append(loanId).append(format.format(date));
	     return sb.toString();
	}
	
	private static Random random;
	/**
	 * @param type 第三方接口名称缩写
	 * @param loanId 申请单号
	 * @return
	 */
	public static String creater() {
		StringBuffer sb = new StringBuffer();
		 
		if(random == null){
			random = new Random() ;
		}
		//65-90 
		char c = (char)(random.nextInt(26)+65);
		sb.append(c).append(System.currentTimeMillis());
		 
	    return sb.toString();
	}
	
	public static String creater(int size) {
		StringBuffer sb = new StringBuffer();
		
		if(random == null){
			random = new Random() ;
		}
		
		for(int i=0;i<size;i++){
			char c = (char)(random.nextInt(26)+65);
			sb.append(c);
		}
		
		
		sb.append(System.currentTimeMillis());
		 
	    return sb.toString();
	}

	public static String getCharacters(int size) {
		StringBuffer sb = new StringBuffer();

		if (random == null) {
			random = new Random();
		}
		// 65-90
		for (int i = 0; i < size; i++) {
			char c = (char) (random.nextInt(26) + 65);
			sb.append(c);
		}
		return sb.toString();
	}

}
